<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>商家后台</title>
<%
	pageContext.setAttribute("APP_PATH", request.getContextPath());
%>
<script type="text/javascript"
	src="${APP_PATH}/static/js/jquery-3.4.1.min.js"></script>
<link
	href="${APP_PATH}/static/bootstrap-3.3.7-dist/css/bootstrap.min.css"
	rel="stylesheet">
<script
	src="${APP_PATH}/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="${APP_PATH}/static/js/jquery_min_341.js"></script>
<link rel="stylesheet" href="${APP_PATH}/static/layui/css/layui.css">


<style type="text/css">
.food {
	margin: auto
}
</style>
<script type="text/javascript">
	function registerCount() {
		var user = $("#loginname").val();
		var password = $("#password").val();
		var tel = $("#tel").val();
		var name = $("#name").val();
		var address = $("#address").val();
		var identity = $("*[name='identity']").val();
		if (user == null || password == null || tel == null
				|| enterPassword == null || name == null || address == null
				|| identity == null) {
			alert("请完善相关信息,您当前的信息为:" + user + password + tel + name + address
					+ identity);
			return false;
		}
		return true;
	}
	function edit(obj) {
		var objChilds = obj.parentNode.parentNode.parentNode.childNodes;
		$("#id").val(objChilds[0].childNodes[0].innerHTML);
		$("#business").val(objChilds[1].childNodes[0].innerHTML);
		$("#name").val(objChilds[2].childNodes[0].innerHTML);
		$("#describe").val(objChilds[3].childNodes[0].innerHTML);
		$("#price").val(objChilds[4].childNodes[0].innerHTML);
	}
	
	
	function findOrder(obj){
		var objChilds = obj.parentNode.parentNode.parentNode.childNodes;
		var id = objChilds[0].childNodes[0].innerHTML;
		alert("接受并完成编号为："+id+"的订单");
		$.ajax({
			type:"post",
			url:"findOrder",
			data:{
				"id":id
			},
			success:function(data){
				if(data){
					alert("接受成功");
				}
			}
		});
		location.reload();
	}

	
	
	
	function update() {
		alert("执行")
		var id = $("#id").val();
		var business = $("#business").val();
		var name = $("#name").val();
		var describe = $("#describe").val();
		var price = $("#price").val();
		$.ajax({
			type : "post",
			url : "updateByPrimaryKeySelective",
			async : false,
			data : {
				"id" : id,
				"business" : business,
				"name" : name,
				"describe" : describe,
				"price" : price
			},
			success : function(data) {
				if (data) {
					alert("修改成功")
				} else {
					alert("修改失败"); //这里data是从ashx文件返回的“账户名或密码不存在..
				}
			}
		});
		location.reload();
	}
</script>
</head>

<body class="layui-layout-body" style="overflow: scroll;">
	<div class="page-header" style="background-color: #C0C1C4"
		align="center">
		<h1 style="color: #477EAD;">${user.name}
			<br> <small>商家后台管理页面</small>
		</h1>
	</div>

	<div class="layui-carousel" style="margin: auto; opacity: 0.9"
		id="test1">
		<div carousel-item style="opacity: 1.0">
			<div align="center">
				<img name="food" src="static/food/food1.jpg">
			</div>
			<div align="center">
				<img name="food" src="static/food/food2.jpg">
			</div>
			<div align="center">
				<img name="food" src="static/food/food3.jpg">
			</div>
			<div align="center">
				<img name="food" src="static/food/food4.jpg">
			</div>
			<div align="center">

				<img name="food" src="static/food/food5.jpg">
			</div>
			<div align="center">

				<img name="food" src="static/food/food6.jpg">
			</div>
			<div align="center">

				<img name="food" src="static/food/food7.jpg">
			</div>
			<div align="center">
				<img name="food" src="static/food/food8.jpg">
			</div>
			<div align="center">
				<img name="food" src="static/food/food9.jpg">
			</div>
			<div align="center">
				<img name="food" src="static/food/food10.jpg">
			</div>

		</div>
	</div>

	<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
		aria-labelledby="mySmallModalLabel">
		<div class="modal-dialog modal-sm" role="document">
			<div class="modal-content">
				<form id="edit">
					<div class="modal-body">
						编号：<input id="id" name="id" disabled class="form-control"
							style="width: 250px"><br> 商家编号：<input id="business"
							name="business" class="form-control" style="width: 250px"><Br>
						菜名：<input id="name" name="name" class="form-control"
							style="width: 250px"><br> 价格：<input id="price"
							name="price" class="form-control" style="width: 250px"><br>
						描述：
						<textarea id="describe" form="edit" name="describe"
							class="form-control" style="width: 250px"></textarea>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" onclick="update()">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</form>
			</div>
		</div>
	</div>

	<div class="layui-tab layui-tab-brief" lay-filter="demo" align="center"
		style="height: 400px">
		<ul class="layui-tab-title" align="center">
			<li class="layui-this">商品管理</li>
			<li>订单管理</li>
			<li>个人管理</li>
		</ul>
		<!-- 编辑模态框 -->


		<div class="layui-tab-content" align="center" style="height: 400px">
			<div class="layui-tab-item layui-show">
				<br>
				<table class="layui-hide" id="table01"></table>
				<div id="barDemo" hidden>
					<a id="save" onclick="edit(this)" class="layui-btn layui-btn-xs"
						lay-event="edit" data-toggle="modal"
						data-target=".bs-example-modal-sm">编辑</a> <a
						onclick="deleteCom(this)"
						class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
				</div>
			</div>

			<div class="layui-tab-item">
				<table class="layui-hide" id="table02"></table>
				<div id="barDemo2" hidden>
 					 <a id="save" onclick="findOrder(this)" class="layui-btn layui-btn-xs" lay-event="edit">接受</a>
				</div>
			</div>
			<div class="layui-tab-item">
				<form action="updateUser"   onsubmit="return registerCount()"
					style="margin-left: auto; margin-right: auto; width: 400px"
					id="register">
					<div class="form-group">
						<label for="id" style="display:inline;">ID：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<input type="text"   class="form-control"
							id="id" name="id" readonly="readonly"
							style="display: inline; width: 200px;" autocomplete="off"
							value="${user.id}" placeholder="${user.id}" /><br />
					</div>


					<div class="form-group">
						<label for="loginname" style="display:inline;">账户：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<input type="text"  readonly="readonly"  class="form-control"
							id="loginname" name="loginname"
							style="display: inline; width: 200px;" autocomplete="off"
							value="${user.loginname}" placeholder="${user.loginname}" /><br />
						<span id="username_span"></span>
					</div>
					<div class="form-group">
						<label for="password" style="display: inline;">密码：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<input type="password" class="form-control" id="password"
							name="password" style="display: inline; width: 200px;"
							value="${user.password}" autocomplete="off"
							placeholder="${user.password}" />
					</div>

					<div class="form-group">
						<label for="name" style="display: inline;">姓名：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<input type="text" class="form-control" id="name" name="name"
							style="display: inline; width: 200px;" placeholder="${user.name}"
							value="${user.name}" autocomplete="off" />
					</div>

					<div class="form-group">
						<label for="tel" style="display: inline;">联系电话：</label> <input
							type="text"
							onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"
							maxlength="11" class="form-control" id="tel" name="tel"
							style="display: inline; width: 200px;" autocomplete="off"
							value="${user.tel}" placeholder="${user.tel}" />
					</div>
					<div class="form-group">
						<label for="address" style="display: inline;">联系地址：</label> <input
							type="text" class="form-control" id="address" name="address"
							style="display: inline; width: 200px;" autocomplete="off"
							value="${user.address}" placeholder="${user.address}" />
					</div>

					<div class="form-group">
						<label for="identity" style="display: inline;">身份：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<input type="text" readonly="readonly" class="form-control" id="identity"
							name="identity" style="display: inline; width: 200px;"
							autocomplete="off" value="${user.identity}"
							placeholder="${user.identity}" />
					</div>

					<input type="submit" rel="external nofollow"
						class="btn btn-primary" value="保存"> <input type="button"
						rel="external nofollow" data-dismiss="modal" class="btn"
						value="关闭">
				</form>
			</div>
		</div>
	</div>



	<br>
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>




	<script src="${APP_PATH}/static/layui/layui.js"></script>
	<script>
		//JavaScript代码区域
		layui.use('carousel', function() {
			var carousel = layui.carousel;
			//建造实例
			carousel.render({
				elem : '#test1',
				width : '50%' //设置容器宽度
				,
				arrow : 'always' //始终显示箭头
				,
				anim : 'default' //切换动画方式
				,
				interval : '2000'
			});
		});
		layui.use('element', function() {
			var element = layui.element;

			//一些事件监听
			element.on('tab(demo)', function(data) {
				console.log(data);
			});
		});

		layui.use('table', function() {
			var table = layui.table;
			var uid =${user.id};
			table.render({
				elem : '#table01',
				url : 'queryBybusiness',
				where : {
					id : uid
				},
				request : {
					pageName : 'page' //页码的参数名称，默认：page
					,
					limitName : 'limit' //每页数据量的参数名，默认：limit
				},
				cellMinWidth : 80,
				cols : [ [ {
					field : 'id',
					width : 200,
					title : 'ID'
				}, {
					field : 'business',
					width : 200,
					title : '商家名'
				} //width 支持：数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度，layui 2.2.1 新增
				, {
					field : 'name',
					width : 200,
					title : '名称'
				}, {
					field : 'describe',
					width : 200,
					title : '描述'
				}, {
					field : 'price',
					width : 200,
					title : '价格'
				}, {
					fixed : 'right',
					width : 200,
					align : 'center',
					toolbar : '#barDemo'
				} ] ],
				page : true
			});
			table.render({
				elem : '#table02',
				url : 'findOrderByBusiness',
				where : {
					id : uid
				},
				request : {
					pageName : 'page' //页码的参数名称，默认：page
					,
					limitName : 'limit' //每页数据量的参数名，默认：limit
				},
				cellMinWidth : 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
				,
				cols : [ [ {
					field : 'id',
					title : 'ID'
				}, {
					field : 'user',
					title : '客户ID'
				} //width 支持：数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度，layui 2.2.1 新增
				, {
					field : 'price',
					title : '已付金额'
				}, {
					field : 'tel',
					title : '电话'
				}, {
					field : 'address',
					title : '地址'
				}, {
					field : 'status',
					title : '状态',
					templet : function(d) {
						console.log(d.status);
						return d.status == 1 ? "已付款" : "已完成" ;
					}
				}, {
					fixed : 'right',
					align : 'center',
					toolbar : '#barDemo2'
				} ] ],
				page : true
			});
		});
		function deleteCom(obj) {
			var objChilds = obj.parentNode.parentNode.parentNode.childNodes;
			var id = objChilds[0].childNodes[0].innerHTML;
			$.ajax({
				type : "post", //post put get 等等
				url : "deleteCommodityById",
				async : false,
				data : { //要传入文件的数据
					"id" : id
				},
				success : function(data) {
					if (data) {
						alert("删除成功")
					} else {
						alert("删除失败"); //这里data是从ashx文件返回的“账户名或密码不存在..
					}
				}
			});
			location.reload();
		}

		//JavaScript代码区域
		layui.use('carousel', function() {
			var carousel = layui.carousel;
			//建造实例
			carousel.render({
				elem : '#test1',
				width : '50%' //设置容器宽度
				,
				arrow : 'always' //始终显示箭头
				,
				anim : 'default' //切换动画方式
				,
				interval : '2000'
			});
		});

		layui.use('element', function() {
			var element = layui.element;
			element.on('tab(demo)', function(data) {
				console.log(data);
			});
		});
	</script>
</body>
</html>
